package com.yuanda.wordhot.web.extensions;

import java.io.IOException;
import java.nio.charset.Charset;

import org.springframework.http.HttpOutputMessage;
import org.springframework.http.MediaType;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.util.StreamUtils;

public class CustomStringHttpMessageConverter extends
		StringHttpMessageConverter {
	// private String encoding;
	private Charset myCharset = Charset.forName("UTF-8");
	private static final MediaType utf8 = new MediaType("text", "plain",
			Charset.forName("UTF-8"));

	@Override
	protected void writeInternal(String s, HttpOutputMessage outputMessage)
			throws IOException {
		// if (this.writeAcceptCharset) {
		// outputMessage.getHeaders().setAcceptCharset(getAcceptedCharsets());
		// }
		// Charset charset = getContentTypeCharset(outputMessage.getHeaders()
		// .getContentType());
		StreamUtils.copy(s, myCharset, outputMessage.getBody());
	}

	@Override
	protected MediaType getDefaultContentType(String t) throws IOException {
		return utf8;
	}
}
